$(function () {
  $('.form-login').bootstrapValidator({

    //设置小图标
    feedbackIcons: {
      valid: 'glyphicon glyphicon-ok',
      invalid: 'glyphicon glyphicon-remove',
      validating: 'glyphicon glyphicon-refresh'
    },

    //设置校验规则
    fields: {

      username: {
        validators: {
          notEmpty: {
            message: "用户名不能为空"
          },
          stringLength: {
            min: 2,
            max: 6,
            message: "用户名长度为2到6为"
          },
          callback:{
            message: "用户名不存在! "
          },
        }
      },
      password: {
        validators: {
          notEmpty: {
            message: ""
          },
          stringLength: {
            min: 6,
            max: 12,
            message: "密码长度为6到12为"
          },
          callback:{
            message: "密码错误！"
          },
        }
      }

    }

  });
  $('.btn-reset').click(function () {
    $('.form-login').data('bootstrapValidator').resetForm()
  })

  $('.form-login').on("success.form.bv", function(e){
    //阻止表单的默认提交
    e.preventDefault();
    $.ajax({
      type:'post',
      url:'/employee/employeeLogin',
      data:$('.form-login').serialize(),
      dataType:'json',
      success:function(res){
        console.log(res)
        if(res.error== 1000){
          $('.form-login').data("bootstrapValidator").updateStatus("username", "INVALID", "callback")
        }
        if(res.error== 1001){
          $('.form-login').data("bootstrapValidator").updateStatus("password", "INVALID", "callback")
        }
        if(res.success== true){
          location.href='index.html'
        }
      }
    })
  })
})